package tool.dialog;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;

/**crea un messaggio di errore con una certa descrizione
 * 
 * @author koldar
 * @version 1.4
 */
public class ErrorDialog extends JDialog implements ActionListener{

	private static final long serialVersionUID = 9163619733676220617L;
	
	// scritte sui componenti.
	private static final String DEFAULT_TITLE = "Error!";
	private static final String TXT_OK = "Ok";
	
	/**indica il messaggio di errore*/
	private JLabel description;
	/**indica il pulsante di ok*/
	private JButton ok;
	
	public ErrorDialog(Frame parent,String title,String description){
		super(parent,title,true);
		this.setLayout(new GridBagLayout());
		GridBagConstraints constraints = new GridBagConstraints();
		this.setSize(200,120);
		
		this.description = new JLabel(description);
		constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.anchor = GridBagConstraints.CENTER;
		this.add(this.description, constraints);
		
		this.ok = new JButton(ErrorDialog.TXT_OK);
		this.ok.setPreferredSize(new Dimension(50, 20));
		constraints.gridx = 0;
		constraints.gridy = 1;
		constraints.anchor = GridBagConstraints.CENTER;
		this.add(ok, constraints);
		
		this.ok.setMnemonic(KeyEvent.VK_ENTER);
		
		this.add(this.description);
		this.add(ok);
		
		this.ok.addActionListener(this);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setVisible(true);
	}
	public ErrorDialog(Frame parent,String description){
		this(parent,DEFAULT_TITLE,description);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		this.dispose();
	}

}
